<!DOCTYPE html>
<html>
	<head>
		<meta charset="utf-8">
		<title></title>
		<script src="vue.js" type="text/javascript"></script>
		<script src="axios.min.js" type="text/javascript"></script>
	</head>
	<body>
		<div id="app">
			<img v-bind:src="item.itemImage">
			{{item.itemName}}<br>
			{{item.itemPrice}}<br>
			{{item.itemDesc}}<br>
			商品评论<br>
			推荐
			
		</div>
	</body>
	<script>
		var config={
			el:"#app",
			data:{
				item:null
			},
			methods:{
				
			},
			mounted:function(){
				debugger;
				console.log("mounted()");
				//从首页跳过来
				//detail.html?itemId=2
				//?itemId=2
				var parameter=location.search;
				 //去掉?
				 parameter=parameter.substr(1);
				 //sringArray[0]=itemId
				 //stringArray[1]=2
				 var stringArray=parameter.split("=");
				 var itemId=stringArray[1];
				 console.log(itemId);
				 var serverUrl="http://localhost:1314"
				 +"/item/findByItemId?id="+itemId;
				 console.log(serverUrl);
				 console.log(this);
				 //mounted中的this代表的是vue,有item属性
				 var vue=this;
				 axios.get(serverUrl)
				 .then(function(response){
					 debugger;
					 var item=response.data;
					 //then函数中this代表的是window,没有 item属性
					 //this.item=item;
					 vue.item=item;
				 })
				 .catch(function(e){
					 window.alert("联网失败");
					 console.log(e);
				 });
			}
		}
		var vue=new Vue(config);
	</script>
</html>



